/*
 * @Date: 2022-07-04 11:09:18
 * @LastEditTime: 2022-07-14 05:38:08
 */
// 用于存储用户登录信息
import Vuex from 'vuex'
import Vue from 'vue'

Vue.use(Vuex)
const getDefaultState = () => {
  return {
    userInfo: {
      uid: '',
      username: '',
      nickname: '',
      sex: '',
      birth: '',
      phone: '',
      email: '',
      pic: ''
    },
    isLogin: false
  }
}
export default new Vuex.Store({
  state () {
    return getDefaultState()
  },
  mutations: {
    updateUserInfo (state, data) {
      state.isLogin = true
      const { uid, username, nickname, sex, birth, phone, email, pic } = data
      state.userInfo.uid = uid
      state.userInfo.username = username
      state.userInfo.nickname = nickname
      state.userInfo.sex = sex
      state.userInfo.birth = birth
      state.userInfo.phone = phone
      state.userInfo.email = email
      state.userInfo.pic = pic
    },
    resetUserInfo (state) {
      Object.assign(state, getDefaultState())
    }
  }
})
